#!/bin/sh

PPPOE_DIR=.
export PATH="$PPPOE_DIR/sbin:$PATH"

if [ ! -d "/etc/ppp" ]; then ln -s /tmp/etc/ppp /etc/ppp; fi
        
pppoe_start ( )
{
if ifconfig eth0; then
	PPPD_PIDFILE="/tmp/pppd.pid"

	USER=$1
	PASSWORD=$2

	if [ "$USER" == "" ] || [ "$PASSWORD" == "" ]; then
		echo "Usage: pppoe.sh start <username> <password>"
		echo "   Ex: pppoe.sh start 74134720@hinet.net wqhatipm"
		return 1
	fi

	echo "Username: $USER"
	echo "Password: $PASSWORD"

	ifconfig eth0 up
	if [ ! -d "/var/run" ]; then mkdir -p /var/run; fi
	
	while [ true ] ; do

  	  $PPPOE_DIR/pppd pty "$PPPOE_DIR/pppoe -p /tmp/pppoe.conf-pppoe.pid.pppoe -I eth0 -T 80 -U  -m 1412" \
	  usepeerdns noipdefault noauth default-asyncmap nodefaultroute password $PASSWORD nodetach mtu 1492 \
	  mru 1492 noaccomp nodeflate nopcomp novj novjccomp user $USER lcp-echo-interval 20 lcp-echo-failure 3 \
	  &
	  echo "$!" > $PPPD_PIDFILE
	  wait

	done

	return 0
else
	return 1
fi

}

pppoe_stop ( )
{
	killall -9 pppoe
        killall -9 pppd
}

case $1 in
	"start")
		pppoe_start $2 $3
		exit $?
	;;

	"stop") 
		pppoe_stop
	;;
esac
exit 0
